package com.itheima.dbservice;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.FocusUserMapper;
import com.itheima.pojo.FocusUser;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class FocusUserServiceApiImpl implements FocusUserServiceApi{
    @Autowired
    private FocusUserMapper focusUserMapper;

    @Override
    public FocusUser getByIdAndUid(Long myId, Long uid) {
        LambdaQueryWrapper<FocusUser> lqw = new LambdaQueryWrapper<>();
        lqw.eq(ObjectUtil.isNotNull(myId), FocusUser::getUserId, myId);
        lqw.eq(ObjectUtil.isNotNull(uid), FocusUser::getFocusId, uid);
        return focusUserMapper.selectOne(lqw);
    }

    @Override
    public void save(FocusUser focusUserInfo) {
        focusUserMapper.insert(focusUserInfo);
    }

    @Override
    public void delete(Long myId, Long uid) {
        LambdaQueryWrapper<FocusUser> lqw = new LambdaQueryWrapper<>();
        lqw.eq(FocusUser::getUserId, myId);
        lqw.eq(FocusUser::getFocusId, uid);
        focusUserMapper.delete(lqw);
    }
}
